package com.block.datapush.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.block.common.service.LogFactory;
import com.block.datapush.model.result.SpePushResut;
import com.block.datapush.service.IDataPushService;
import com.block.datapush.special.service.IDataPushSelfSpecialService;
import com.block.db.entity.MemberExtInfo;
import com.block.db.mapper.MemberExtInfoMapper;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class DataPushServiceImpl implements IDataPushService {

    private static Logger log = LogFactory.getThridLog();

    @Resource
    MemberExtInfoMapper memberExtInfoMapper;
    @Autowired
    IDataPushSelfSpecialService dataPushSelfSpecialService;

    @Override
    public SpePushResut memberCheckHandle(Long userId) {

        SpePushResut spePushResut = new SpePushResut();
        spePushResut.setPushSuccess(false);

        // 查询用户的基本信息和认证信息
        MemberExtInfo memberExtInfo = memberExtInfoMapper.selectById(userId);
        if (ObjectUtil.isEmpty(memberExtInfo)){
            log.error("【数据推送】有数据信息为空【userId】{}", userId);
            return spePushResut;
        }

        /**
         * 普通机构的撞库操作
         */
        spePushResut = dataPushSelfSpecialService.dataCheckHandle(memberExtInfo);
        spePushResut.setUid(memberExtInfo.getUid());
        if (spePushResut.isPushSuccess()){
            // 推送成功，则进行消息通知
            // 非机构单推，则继续进行api 推送
            return spePushResut;
        }

        return spePushResut;
    }
}
